package me.xue.communityhealth.service;

import me.xue.communityhealth.repo.DepartmentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class DepartmentService implements BaseService<String,String> {

    private final DepartmentRepository departmentRepository;

    @Autowired
    public DepartmentService(DepartmentRepository departmentRepository) {
        this.departmentRepository = departmentRepository;
    }

    @Override
    public int save(String departmentName) {
        return StringUtils.isEmpty(departmentName) ? 0 : departmentRepository.save(departmentName);
    }

    @Override
    public int update(String s) {
        return 0;
    }

    public int updateDepartment(String oldDepartment, String newDepartment) {
        if (StringUtils.isEmpty(oldDepartment) || StringUtils.isEmpty(newDepartment)) {
            return 0;
        }
        return departmentRepository.update(oldDepartment, newDepartment);
    }

    @Override
    public int delete(String which) {
        return StringUtils.isEmpty(which) ? 0 : departmentRepository.delete(which);
    }

    @Override
    public List<String> findAll() {
        return departmentRepository.findAll();
    }
}
